home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscSoundPalette / MiscSoundUtil.subproj / MiscVolumeLight.m < prev    next >
Encoding:
Text File  |  1995-03-25  |  3.3 KB  |  129 lines

  1. /*
  2.  
  3. MiscVolumeLight
  4. Version 1.2
  5. Copyright (c) 1995 by Sean Luke
  6. Donated to the MiscKit
  7.  
  8. Permission to use, copy, modify, and distribute this material 
  9. for any purpose and without fee, under the restrictions as noted 
  10. in the MiscKit copyright notice, is hereby granted, provided that
  11. the MiscKit copyright notice and this permission notice 
  12. appear in all source copies, and that the author's name shall not
  13. be used in advertising or publicity pertaining to this 
  14. material without the specific, prior written permission 
  15. of the author.  SEAN O. LUKE  MAKES NO REPRESENTATIONS ABOUT THE
  16. ACCURACY OR SUITABILITY OF THIS MATERIAL FOR ANY PURPOSE.  
  17. IT IS PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  18.  
  19. */
  20.  
  21. #import "MiscVolumeLight.h"
  22. #import <stdio.h>
  23.  
  24. @implementation MiscVolumeLight
  25.  
  26. - drawSelf:(const NXRect*) rects:(int) rectCount
  27.     {
  28.     int just_erase=0;
  29.     float left,right;
  30.     NXRect backgroundRect=bounds;
  31.     
  32.     //printf ("Displaying\n");
  33.     
  34.     if ([delegate respondsTo:@selector(meterWillUpdate:)])
  35.         [delegate meterWillUpdate:self];
  36.  
  37. //    if (![window isVisible]) return self;        // no window to draw in.
  38.     
  39.     //printf ("Window Visible\n");
  40.     
  41.     //if (![window isVisible]) return NULL;        // no window to draw in.
  42.     // the above has been turned off because when loading Resound,
  43.     // the sound meter wouldn't display until a sound was being played
  44.     // or recorded!
  45.     
  46.     
  47.     // first to check to see if the sound lock is current
  48.     ////printf ("Meter\n");
  49.     if (sound!=NULL)
  50.         {
  51.         int status=NX_SoundStopped;
  52.         id actual_sound=NULL;            // quiets compiler complaints
  53.         
  54.         //printf ("Sound ain't Null\n");
  55.         
  56.         if ([sound isKindOf:[Sound class]]) 
  57.             {actual_sound=sound;}
  58.         else if ([sound isKindOf:[SoundView class]])
  59.             {actual_sound=[sound soundBeingProcessed];}
  60.         status=[actual_sound status];
  61.         if (status==NX_SoundStopped||
  62.             status==NX_SoundInitialized||
  63.             status==NX_SoundFreed) 
  64.         {just_erase=1;}
  65.             
  66.         // Then modify the meter to match the sound    
  67.         
  68.         else if (status==NX_SoundRecordingPaused||
  69.                  status==NX_SoundRecording||
  70.                  status==NX_SoundRecordingPending)
  71.         {[self setToInput];}
  72.         
  73.         else if (status==NX_SoundPlayingPaused||
  74.                  status==NX_SoundPlaying||
  75.                  status==NX_SoundPlayingPending)
  76.         {[self setToOutput];}
  77.         
  78.         if ([actual_sound channelCount]>1)
  79.             {[self setStereo];}
  80.         else {[self setMono];}
  81.         }
  82.     
  83.  
  84.     
  85.     
  86.     
  87.     if (bezeled)
  88.         {
  89.         backgroundRect.origin.x        +=VOLUMEMETER_BACKGROUND_INSET; 
  90.         backgroundRect.size.width    -=VOLUMEMETER_BACKGROUND_INSET*2;
  91.         backgroundRect.origin.y        +=VOLUMEMETER_BACKGROUND_INSET; 
  92.         backgroundRect.size.height    -=VOLUMEMETER_BACKGROUND_INSET*2;
  93.         }
  94.     
  95.     if (!VOLUMEMETER_can_draw(&bounds)) return self;    // can't draw
  96.     //printf("Big enough\n");
  97.     if (bezeled) NXDrawGrayBezel(&bounds,NULL);
  98.  
  99.     if (running&&!just_erase)
  100.         {
  101.         //printf ("DRAWING!\n");
  102.         left=0;right=0;
  103.         
  104.         if (input&&input_device!=NULL) 
  105.             [input_device getPeakLeft:&left right:&right];
  106.         
  107.         if ((!input)&&output_device!=NULL)
  108.             [output_device getPeakLeft:&left right:&right];
  109.             
  110.         if (left>1) left=1; if (right>1) right=1;
  111.             // occasionally a NeXTSTEP bug returns values larger than 1!
  112.         
  113.         PSsetgray((left+right)/2.0);
  114.         NXRectFill(&backgroundRect);
  115.         }
  116.     just_erase=0;
  117.     NXPing();
  118.     if ([delegate respondsTo:@selector(meterDidUpdate:)])
  119.         [delegate meterDidUpdate:self];
  120.     return self;
  121.     }
  122.  
  123. - (const char*) getInspectorClassName
  124.     {
  125.     return "MiscVolumeLightInspector";
  126.     }
  127.  
  128.  
  129. @end